package com.spc.demo.listener;

import com.spc.demo.service.ListenerService;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationObserver;

import java.io.File;

/**
 * @author pingchao.su
 * @date 2022/9/5 19:58
 */
public class FileListener extends FileAlterationListenerAdaptor {

    // 声明业务服务
    private ListenerService listenerService;

    // 采用构造函数注入服务
    public FileListener(ListenerService listenerService) {
        this.listenerService = listenerService;
    }

    @Override
    public void onFileCreate(File file) {
        System.out.println("文件创建执行");
    }

    @Override
    public void onFileChange(File file) {
        System.out.println("文件创建修改");
    }

    @Override
    public void onFileDelete(File file) {
        System.out.println("文件创建删除");
    }

    @Override
    public void onDirectoryCreate(File directory) {
        System.out.println("目录创建");
    }

    @Override
    public void onDirectoryChange(File directory) {
        System.out.println("目录修改");
    }

    @Override
    public void onDirectoryDelete(File directory) {
        System.out.println("目录删除");
    }

    @Override
    public void onStart(FileAlterationObserver observer) {
        System.out.println("轮询开始");
    }

    @Override
    public void onStop(FileAlterationObserver observer) {
        System.out.println("轮询结束");
    }
}
